<?php include HEADER; ?>

<div class="wrap-pd" itemscope="" itemtype="http://data-vocabulary.org/Product"> 
  <script type="text/javascript">
        $(document).ready(function () {
            fPosition_Fix();
        })
    </script>
  <div class="wrap-left-pd" style="top: 7px;">
    <div class="pro-image">
      <p class="icon-cr  "> </p>
      <a class="pro-image-large"> <img itemprop="image" src="<?php echo __URL_BASE ?>images/<?php echo utility::setImageThumb($Tivi->Images,$Tivi->Images2,$Tivi->Images3,$Tivi->Images4,$Tivi->Images5);?>" alt="TV LED LG  47LB561T 47 inches Full HD" title="TV LED LG  47LB561T 47 inches Full HD"></a>
      <div class="cl"> </div>
        <!--danh sách ảnh thumb-->
       	<ul class="ls pro-image-list">      
            
            <?php
			for($i=1;$i<=5;$i++)
			{
				$img = 'Images'.$i;
				if($i==1) $img = 'Images';
				if($Tivi->$img && $Tivi->$img != '')
				{
				?>
					 <li><a class="fancybox-thumb" rel="fancybox-thumb" href="<?php echo __URL_BASE ?>images/<?php echo $Tivi->$img ?>">
						<img src="<?php echo __URL_BASE ?>images/<?php echo $Tivi->$img ?>" alt="<?php echo $Tivi->TenTivi ?>" title="<?php echo $Tivi->TenTivi ?>"></a>
					</li>
				<?php	
				}
			}
			?>
            
        </ul>
        <!--ket thuc danh sách ảnh thumb-->
      <div class="cl"> </div>
      <div class="pro-price-fix pro-price-fix-hidden">
        <p class="pd-name"><?php echo $Tivi->TenTivi ?></p>
        <div class="pro-price-large">
          <div class="p-price-mediamart">
            <div class="over-price-number">
              <div class="price price-number"> <?php echo number_format($Tivi->GiaBan,0,'','.') ?>đ <span class="price-number-d-6 price-number-d"></span> </div>
            </div>
          </div>
          <div class="cl"> </div>
          <div class="p-price">
            <div class="p-price-market"> <span class="title">Giá chính hãng :</span> <span class="price"> <?php echo number_format($Tivi->GiaThat,0,'','.') ?>đ</span> </div>
            <div class="p-price-save"> <span class="title">Tiết kiệm :</span> 
            	<span class="price"><?php echo number_format($Tivi->GiaThat - $Tivi->GiaBan,0,'','.') ?> đ</span> </div>
           <!-- <div class="p-price-installment"> <span class="title">Mua trả góp từ :</span> <span class="price">861.250 đ/tháng</span> </div>-->
          </div>
          <a class="p-order-buy" href="<?php echo __URL_BASE ?>index.php?rt=cart/addcart&tivi_id=<?php echo $Tivi->id ?>" title="Mua Online" rel="nofollow" target="_self"> </a>
          <div class="cl"> </div>
          <div class="p-specialoffer">
            <h3> TÍNH NĂNG CHÍNH CỦA SẢN PHẨM</h3>
            <div class="cl"> </div>
            <p>
            <?php
			 	$arr = json_decode($Tivi->TinhNang);
				if(count($arr)>0)
					foreach($arr as $k=>$v){
						echo '- '.$v.'<br />';
					}
			  ?>
            </p>
            <div class="cl"> </div>
          </div>
          <div class="cl"> </div>
          
        </div>
      </div>
    </div>
  </div>
  <div class="wrap-right-pd">
    <div class="pro-detail">
      <h1 itemprop="name"><?php echo $Tivi->TenTivi ?></h1>
      <div class="p-model" itemscope="" itemtype="http://data-vocabulary.org/Review">
        <h3 itemprop="itemreviewed"> Model:  47LB561T</h3>
        <span>|</span> <span>Mã hàng: 105027</span> </div>
      <div class="border-line"> </div>
      <div class="p-spec" itemprop="description">
        <p> - Màn hình <?php echo $Tivi->KichThuoc; ?> inches<br>
          - Độ phân giải: <?php echo $Tivi->PhanGiai; ?><br>
          <?php
		  	if(count($arr)>0)
         		foreach($arr as $k=>$v){
					echo '- '.$v.'<br />';
				}
		  ?>
        <div class="cl"> </div>
      </div>
      <div class="border-line"> </div>
      <div class="cl"> </div>
      <div class="cl"> </div>
    </div>
    <div class="pro-price ">
      <div class="daily-deal"> </div>
      <div class="cl"> </div>
      <div class="p-price-mediamart">
        <div class="over-price-number">
          <div class="price price-number"> <?php echo number_format($Tivi->GiaBan,0,'','.') ?>đ</div>
        </div>
      </div>
      <div class="p-price p-price-market"> <span class="title">Giá chính hãng :</span> <span class="price"> <?php echo number_format($Tivi->GiaThat,0,'','.') ?> đ</span> </div>
      <div class=" p-price p-price-save" itemprop="price"> <span class="title">Tiết kiệm :</span> <span class="price"><?php echo number_format($Tivi->GiaThat - $Tivi->GiaBan,0,'','.') ?>đ đ</span> </div>
      <!--<div class=" p-price p-price-installment"> <span class="title">Mua trả góp từ :</span> <span class="price">861.250 đ/tháng</span> </div>-->
      <ul class="ls p-installment-cart">
        <li><a class="p-order-buy" href="<?php echo __URL_BASE ?>index.php?rt=cart/addcart&tivi_id=<?php echo $Tivi->id ?>" title="Mua Online" rel="nofollow" target="_self"> </a></li>
      </ul>
      <div class="cl"> </div>
      <div class="p-phone-support-bg"> <a class="fancybox fancybox.ajax" rel="nofollow" title="Tổng đài Tư Vấn Bán hàng Online MediaMart: 04 6262 8888" href="<?php echo __URL_BASE ?>http://mediamart.vn/Shared/SupportOnline"></a> </div>
    </div>
    <div class="cl" style="height: 14px;"> </div>
    
  
    <div class="pd-sameprice">
      <h4> <span>Có thể bạn thích sản phẩm này</span> </h4>
      <ul class="ls pd-sameprice-item">
      <?php $tv = new tivi(); 
	  		$lstTivi_random = $tv->getTiviByWhere('t.id <> '.$Tivi->id, 'rand() limit 0,5'); 
			if(count((array)$lstTivi_random) > 0) :
				foreach($lstTivi_random as $item){
		?>
					<li>
						  <p class="image"> <a href="<?php echo __URL_BASE ?>tivi/chi-tiet-san-pham/<?php echo $item->id ?>/<?php echo utility::utf8tourl(trim($item->TenTivi));  ?>.html" > <img src="<?php echo __URL_BASE ?>images/<?php echo utility::setImageThumb($item->Images,$item->Images2,$item->Images3,$item->Images4,$item->Images5);  ?>" title=<?php echo $item->TenTivi ?>" alt="<?php echo $item->TenTivi ?>"> </a> </p>
						  <a href="<?php echo __URL_BASE ?>tivi/chi-tiet-san-pham/<?php echo $item->id ?>/<?php echo utility::utf8tourl(trim($item->TenTivi));  ?>.html" title="<?php echo $item->TenTivi ?> " > <?php echo $item->TenTivi ?> </a>
						  <p class="price1"><?php echo number_format($item->GiaBan,0,'','.') ?>đ</p>
					</li>
        <?php			
				}
			endif;
		?>
      </ul>
      <div class="cl"> </div>
    </div>
    <div class="cl"> </div>
    <div class="p-introduct">
      <ul class="ls p-introduct-title">
        <li><a href="javascript:;" class="active" rel="#p-introduct-news" title="Giới thiệu sản phẩm"> Giới thiệu</a> </li>
        <li><a href="javascript:;" rel="#p-introduct-spec" class="" title="Thông số kỹ thuật"> Thông số kỹ thuật</a> </li>
        
      </ul>
      <div class="cl"> </div>
      <div id="p-introduct-news" class="p-introduct-content p-introduct-content-active">
       
        <div class="p-news">
          <?php echo $Tivi->MoTa ?>
        </div>
        <div class="cl"> </div>
      </div>
      <div id="p-introduct-spec" class="p-introduct-content ">
        <div class="p-introduct-spec-input">
          <?php echo $Tivi->ThongSoKyThuat ?>
        </div>
        <div class="cl"> </div>
      </div>
     
      
      <div class="cl"> </div>
    </div>
   
    <div class="cl"> </div>
 	<div class="comment">
		<h2>BÌNH LUẬN</h2>
  <?php if(isset($lstComment)) : 
  		$userModel = new user();
  ?>
			<div class="commentlst">
				<div class="commenting">
				
				  
			<?php foreach($lstComment as $item) :?>
					<div class="item">
						<div class="rgt">&nbsp;
							
							<a  onclick="ShowReply(<?php echo $item->id ?>);"><span class="chatico"></span>Nhận xét</a>
							
						</div>
						<img src="<?php echo __URL_BASE?>img/ichat.gif">
						<b><?php $user = $userModel->getUserByTenDangNhap($item->tendangnhap); echo $user->HoTen ?></b> <span>(<strong><?php echo $user->Email ?></strong>)</span>
						<div class="period"><?php echo date('d-m-Y G:i:s',strtotime($item->thoigian)) ?></div>
						<div class="cmmt_cont"><?php echo $item->noidung ?></div>
						<?php 
							$commentModel = new comment();
							$lstchild = $commentModel->getCommentByParentId($item->id,'trangthai = 1 and trangthai=1');
							if($lstchild) : 
								foreach($lstchild as $child) :
						?>
									<div class="initem">
										<img src="<?php echo __URL_BASE?>img/ichat.gif">
										<b><?php $user = $userModel->getUserByTenDangNhap($child->tendangnhap); echo $user->HoTen ?></b> <span>(<strong><?php echo $user->Email ?></strong>)</span>
										<div class="period"><?php echo date('d-m-Y G:i:s',strtotime($child->thoigian)) ?></div>
										<div class="cmmt_cont"><?php echo $child->noidung ?></div>
									</div>
						<?php		
								endforeach;
							endif; // end lstchild
						?>
						
						<div id="replybox<?php echo $item->id ?>"></div>
					</div>
			<?php endforeach;   ?>
					
				</div>
			</div> <!--end commentlst-->
	<?php endif; //end lstcomment?>
		<div class="cl10"></div>
		<div class="commentbox">
			<textarea id="txComment" name="comment" maxlength="500" title="" class="" placeholder="Nội dung bình luận của bạn..."></textarea>
			<div class="val_group">
				<div class="cl5"></div>
				<div class="comment_msg">Vui lòng gõ tiếng Việt có dấu</div>
				<?php if(isset($_SESSION['user'])){ ?>
						<input class="action" type="button" id="btnsendcomment" value="Gửi đi" >
				<?php } 
					  else{ ?>
						<a class="fancybox action" data-fancybox-type="iframe" href="<?php echo __URL_BASE ?>index.php?rt=user/login&request=login" title="Đăng nhập" style="text-decoration: none;"> Gửi đi</a>
				<?php } ?>
				
				<div class="comment_counter">Ký tự còn lại: 500</div>
				<div class="clr"></div>
			</div>
		</div>
		<div class="clr"></div>
		
	</div> <!--end comment-->
	<div class="cl"> </div>
    <div class="pd-sameprice">
      <h4> <span>Sản phẩm cùng hãng</span> </h4>
      <ul class="ls pd-sameprice-item">
        <?php $tv = new tivi(); 
	  		$lstTivi_same = $tv->getTiviByWhere('t.id <> '.$Tivi->id.' and idHangSanXuat = '.$Tivi->idHangSanXuat, 'rand() limit 0,5'); 
			if(count((array)$lstTivi_same) > 0) :
				foreach($lstTivi_same as $item){
		?>
					<li>
						  <p class="image"> <a href="<?php echo __URL_BASE ?>tivi/chi-tiet-san-pham/<?php echo $item->id ?>/<?php echo utility::utf8tourl(trim($item->TenTivi));  ?>.html" > <img src="<?php echo __URL_BASE ?>images/<?php echo utility::setImageThumb($item->Images,$item->Images2,$item->Images3,$item->Images4,$item->Images5); ?>" title=<?php echo $item->TenTivi ?>" alt="<?php echo $item->TenTivi ?>"> </a> </p>
						  <a href="<?php echo __URL_BASE ?>tivi/chi-tiet-san-pham/<?php echo $item->id ?>/<?php echo utility::utf8tourl(trim($item->TenTivi));  ?>.html" title="<?php echo $item->TenTivi ?> " > <?php echo $item->TenTivi ?> </a>
						  <p class="price1"><?php echo number_format($item->GiaBan,0,'','.') ?>đ</p>
					</li>
        <?php			
				}
			endif;
		?>
      </ul>
      <div class="cl"> </div>
    </div>
    <div class="cl"> </div>
   
  </div>
  <div class="cl"> </div>
</div>
<?php include FOOTER; ?>
<script>
	$(document).ready(function(){
		//add a scrool when commentlst div's height > 500pxalert($(".commentlst").height());
		if($(".commentlst").height() >= 500) $(".commentlst").css('overflow-y','scroll');
		//check count character comment box
		$("#txComment").keyup(function(){
			comment_length = $("#txComment").val().length;
			char_remain = 500 - comment_length;
			$(".comment_counter").html('Ký tự còn lại: '+char_remain);
		});
		//insert comment
		$("#btnsendcomment").click(function(){
			comment = $("#txComment").val();
			parent_id = 0;
			if(comment == ''){alert('Nội dung không được để trống.'); return false;}
			$.ajax({
				url:"<?php echo __URL_BASE ?>index.php?rt=comment/insert&tivi_id=<?php echo $_REQUEST['tivi_id'] ?>",
				type: 'post',
				datatype: 'html',
				data: {comment:comment,parent_id: parent_id},
				success:function(data){
					//$("#a").html(data);return false;
					if(data=='1'){ 
						alert('Xin chân thành cảm ơn bạn đã chia sẻ cùng chúng tôi. Chúng tôi sẽ kiểm duyệt và cập nhật những thông tin của bạn lên website trong thời gian sớm nhất có thể.');
						$("#txComment").val('');
					}
					else alert('Có lỗi xảy ra. Mời bạn thử lại.');
				}	
			});
		});
	});
	//show reply box
	function ShowReply(id){
		<?php if(isset($_SESSION['user'])){ ?>
				btsubmit = '<input type="submit" class="action" value="Gửi đi" onclick="return DoReply('+id+');"> ';
		<?php } 
			  else{ ?>
				btsubmit = '<a class="fancybox action" data-fancybox-type="iframe" href="<?php echo __URL_BASE ?>index.php?rt=user/login&request=login" title="Đăng nhập" style="text-decoration: none;color:#fff"> Gửi đi</a>';
		<?php } ?>
		$("div[id^=replybox]").html('');
		$("div[id=replybox"+id+"]").html('<div class="replybox" id="frmReply">'+
		'<p><img src="http://static.bongdaplus.vn/themes/master/img/ichat.gif"><strong>Nhận xét của bạn:</strong></p>'+
		'<div class="replyitem">'+
			'<input id="hdCommentID" name="ref" type="hidden" value="156020">'+
			'<textarea id="txrepComment" name="reply"></textarea>'+
			'<div class="cl10"></div>'+
			'<div class="rgt">'+
				btsubmit+
				'<input type="reset" class="action alt" value="Bỏ qua" onclick="HideReply();">'+
			'</div>'+
			'<p class="replyerror"> &nbsp; • Vui lòng gõ tiếng Việt có dấu</p>'+
			'<p class="replyerror" id="errMsg" style="display: none;"> &nbsp; • Vui lòng nhập nội dung nhận xét</p>'+
			'<div class="clr"></div>'+
		'</div>'+
	'</div>');
		//add a scrool when commentlst div's height > 500px
		
		if($(".commentlst").height() >= 500) $(".commentlst").css('overflow-y','scroll');
	}
	
	//hide reply box
	function HideReply(){
		$("div[id^=replybox]").html('');
		if($(".commentlst").height() <= 500) $(".commentlst").css('overflow-y','auto');
	}
	
	//insert comment reply
	function DoReply(parent_id){
		//alert(parent_id);
		comment = $("#txrepComment").val();
			if(comment == ''){alert('Nội dung không được để trống.'); return false;}
			$.ajax({
				url:"<?php echo __URL_BASE ?>index.php?rt=comment/insert&tivi_id=<?php echo $_REQUEST['tivi_id'] ?>",
				type: 'post',
				datatype: 'html',
				data: {comment:comment,parent_id: parent_id},
				success:function(data){
					//$("#a").html(data);return false;
					if(data=='1'){ 
						alert('Xin chân thành cảm ơn bạn đã chia sẻ cùng chúng tôi. Chúng tôi sẽ kiểm duyệt và cập nhật những thông tin của bạn lên website trong thời gian sớm nhất có thể.');
						$("div[id^=replybox]").html('');
					}
					else alert('Có lỗi xảy ra. Mời bạn thử lại.');
				}	
			});
	}
	$("#txComment").keyup(function(){
		content = $("#txComment").val();
		if($.trim(content) == ''){
			$("#txComment").val('');
		}
	});
	$(document).on("keyup","#txrepComment",function(){
		content = $("#txrepComment").val();
		if($.trim(content) == ''){
			$("#txrepComment").val('');
		}
	});
</script>
<!--<div id="a"></div>-->